package com.example.sqlitetest.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sqlitetest.R;
import com.example.sqlitetest.db.MyDataBaseHelper;
import com.example.sqlitetest.model.HomeWorkInfo;

import java.util.List;

public class HomeWorkAdapter extends BaseAdapter {
    //定义数据
    private List<HomeWorkInfo> mData;
    //定义Inflater,加载我们自定义的布局
    private LayoutInflater mInflater;
    //定义上下文
    private Context con;

    private MyDataBaseHelper mHelper;

    //定义构造器
    public HomeWorkAdapter(Context context, LayoutInflater inflater, List<HomeWorkInfo> data) {
        con = context;
        mInflater = inflater;
        mData = data;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View viewStudent = mInflater.inflate(R.layout.list_item_4,null);
        HomeWorkInfo homework = mData.get(position);

        final TextView studentNo = (TextView)viewStudent.findViewById(R.id.studentNo);
        final TextView name = (TextView)viewStudent.findViewById(R.id.name);

        //获得自定义布局中每一个控件的对象
        TextView className = (TextView) viewStudent.findViewById(R.id.className);
        TextView english = (TextView) viewStudent.findViewById(R.id.english);
        TextView chinese = (TextView) viewStudent.findViewById(R.id.chinese);
        TextView math = (TextView) viewStudent.findViewById(R.id.math);
        TextView total = (TextView) viewStudent.findViewById(R.id.total);

        //将数据添加到自定义的布局中去
        name.setText(homework.getName());
        english.setText(String.valueOf(homework.getEnglish()));
        chinese.setText(String.valueOf(homework.getChinese()));
        math.setText(String.valueOf(homework.getMath()));


        return viewStudent;
    }

}
